package com.honey.solr.daosupport.method;

import com.honey.compilation.java.Method;
import com.honey.compilation.java.Parameter;
import com.honey.generator.java.AbstractClassName;
import com.honey.solr.SolrConstant;
import com.honey.solr.SolrFactory;

public class Query5Method extends AbstractClassName {
	

	private SolrFactory solrFactory = null;
	
	public Query5Method(SolrFactory solrFactory ){
		this.solrFactory =solrFactory;
	}
	public Method createMethod(){
		Method answer =null;
		boolean bool = solrFactory.getSolrPlugin().getQueryForPage() != null ;
			
		answer = new Method("query");
		answer.setReturnType(SolrConstant.QUERY_RESPONSE);
		answer.addException(SolrConstant.SOLR_SERVER_EXCEPTION);
		
		Parameter parameter = new Parameter(solrFactory.getConditionType(),"condition");
		answer.addParameter(parameter);
		parameter.addJavaDocLine("动态查询条件.");
		
		if(bool){	
			parameter = new Parameter(solrFactory.getSolrPlugin().getQueryForPage(),"page");
			parameter.addJavaDocLine("分页参数.");
			answer.addParameter(parameter) ;
			
		}	
		answer.addBodyLine("SolrQuery solrQuery = new SolrQuery()");
		answer.addBodyLine("solrQuery.setQuery(this."+SolrConstant.CONDITION_ADAPTERTO_QUERY+"(condition))");
		
		answer.addBodyLine("return query( solrQuery"+(bool?", page ":"")+")") ;
	
		return answer;
	}
}
